//
//  BusinessViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/8.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "DiscoverSupplyDetailProductViewController.h"
#import "RDVTabBarController.h"
#import "RDVTabBarItem.h"
#import "ServiceView.h"
#import "peisongCell.h"
#import "HttpRequest.h"
#import "UIButton+WebCache.h"
#import "HAODEsingleton.h"
#import "ProductView.h"
#import "MapViewControllers.h"
#import <MapKit/MapKit.h>
#import "ACETelPrompt.h"
#import "proview.h"
#import "UMSocial.h"
#import "DiscoverSupplyAgencyViewController.h"
@interface DiscoverSupplyDetailProductViewController ()<CLLocationManagerDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UIScrollViewDelegate,UMSocialUIDelegate>
@property (nonatomic, unsafe_unretained) NSInteger currentIndex;
@property(nonatomic ,strong)NSDictionary*myDic;
@property(nonatomic,strong)   NSString*shuoming;
@property(nonatomic,strong)   NSString*shareUrl;

@end

@implementation DiscoverSupplyDetailProductViewController
{
    HAODEsingleton *commdity;
    ServiceView *mainScorllView;
    UIScrollView*mainScroll;
    UIScrollView*mainScroll1;
    NSMutableArray*LinkType;
    NSMutableArray*LinkCode;
    NSMutableArray*ImageUrl1;
    UIButton*guanzhuBtn;
    proview * proView;
    UIScrollView *scroll3;
    UIView*view;
    NSArray *product;
    UIView*fengxiangview;
    UIButton* quxiao;
    UIScrollView*fengxiangScroll;
    NSDictionary*dataDicts;
}
@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}


-(void)closeKeyBoad
{
    [fengxiangview removeFromSuperview];
    [fengxiangScroll removeFromSuperview];
    [quxiao removeFromSuperview];
    
}
-(void)fenxiangss:(UIButton*)sender{
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"Supply" forKey:@"contentType"];
    [param setValue:commdity.reqId forKey:@"contentId"];
    //    [param setValue:@"wx_single" forKey:@"shareTarget"];
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    
    [HttpRequest requestData:@"Discover/getShareUrl" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                self.shuoming=[severDataDict.dataDict objectForKey:@"shareDescription"];
                self.shareUrl=[severDataDict.dataDict objectForKey:@"shareUrl"];
                
                fengxiangview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
                fengxiangview.backgroundColor=[UIColor blackColor];
                fengxiangview.alpha=0.5;
                [self.view addSubview:fengxiangview];
                
                fengxiangScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,ScreenHeight-240, ScreenWidth,200)];
                fengxiangScroll.delegate = self;
                fengxiangScroll.userInteractionEnabled = YES;
                fengxiangScroll.scrollEnabled = YES;
                fengxiangScroll.showsVerticalScrollIndicator = FALSE;
                fengxiangScroll.showsHorizontalScrollIndicator = FALSE;
                fengxiangScroll.backgroundColor=[UIColor whiteColor];
                [self .view addSubview:fengxiangScroll];
                
                // 手势
                UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
                singleFingerOne.numberOfTouchesRequired = 1; //手指数
                singleFingerOne.numberOfTapsRequired = 1; //tap次数
                singleFingerOne.delegate = self;
                [fengxiangview addGestureRecognizer:singleFingerOne];
                
                
                
                
                NSArray*nameBtn=[[NSArray alloc]initWithObjects:@"发送給朋友",@"分享到朋友圈",nil];
                NSArray *arrayimage = @[@"faweixin",@"fenxiangpenyouquan"];
                for (int i = 0; i<2; i++) {
                    UIButton *nameButcenter = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/3*i,   80*ScreenHeight/1334+15, ScreenWidth/3, 60)];
                    
                    [fengxiangScroll addSubview:nameButcenter];
                    
                    
                    UIButton *nameBut = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/3*i,   nameButcenter.bottom+20, ScreenWidth/3, 14)];
                    [nameBut setTitle: [nameBtn objectAtIndex:i]  forState:UIControlStateNormal];
                    nameBut.tag=201+i;
                    [nameBut setTitleColor:shenhuicolor forState:0];
                    nameBut.titleLabel.font=[UIFont systemFontOfSize:14];
                    [nameBut addTarget:self action:@selector(fengxiang:) forControlEvents:UIControlEventTouchUpInside];
                    [fengxiangScroll addSubview:nameBut];
                    
                    
                    UIButton *wuyebuttonimage = [UIButton buttonWithType:UIButtonTypeCustom];
                    wuyebuttonimage.frame = CGRectMake(ScreenWidth/3*i,  10, 60, 60);
                    
                    wuyebuttonimage.tag = 201+i;
                    wuyebuttonimage.center=nameButcenter.center;
                    [wuyebuttonimage setImage:[UIImage imageNamed: [arrayimage objectAtIndex:i]] forState:UIControlStateNormal];
                    [wuyebuttonimage addTarget:self action:@selector(fengxiang:) forControlEvents:UIControlEventTouchUpInside];
                    [fengxiangScroll addSubview:wuyebuttonimage];
                    
                    
                }
                
                
                quxiao = [[UIButton alloc] initWithFrame:CGRectMake(0,ScreenHeight-45,  ScreenWidth, 45)];
                [quxiao setTitle:@"取消" forState:UIControlStateNormal];
                quxiao.titleLabel.font=[UIFont systemFontOfSize:16];
                quxiao.backgroundColor=[UIColor whiteColor];
                [quxiao setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [quxiao addTarget:self action:@selector(closeKeyBoad) forControlEvents:UIControlEventTouchUpInside];
                [self .view addSubview:quxiao];
                UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, ScreenWidth-30, 0.35)];
                line.backgroundColor=qianhuicolor;
                [quxiao addSubview:line];
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
    
}

-(void)fengxiang:(UIButton*)sender{
    [fengxiangview removeFromSuperview];
    [fengxiangScroll removeFromSuperview];
    [quxiao removeFromSuperview];
    NSURL *url = [NSURL URLWithString:commdity.ImageUrl];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *image1 = [[UIImage alloc] initWithData:data];
    if (sender.tag==201) {
        if (![commdity.content isEqualToString:@""]) {
            self.shuoming=commdity.content;
        }
        [UMSocialData defaultData].extConfig.wechatSessionData.title =  commdity.title;
        UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeDefault url:self.shareUrl];
        
        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatSession].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
        [UMSocialData defaultData].extConfig.wechatSessionData.url = self.shareUrl;
        [[UMSocialDataService defaultDataService]postSNSWithTypes:@[UMShareToWechatSession] content:self.shuoming image:image1 location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *response){
            
            if (response.responseCode == UMSResponseCodeSuccess) {
                NSLog(@"分享成功！");
            }
            
        }];
        
        
        
        
        
        
    }
    
    if (sender.tag==202) {
        
        //[UMSocialData defaultData].extConfig.wechatSessionData.title =[commdity.Dict objectForKey:@"itemName"];
        UMSocialUrlResource *urlResource = [[UMSocialUrlResource alloc] initWithSnsResourceType:UMSocialUrlResourceTypeDefault url:self.shareUrl];
        [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToWechatTimeline].snsClickHandler(self,[UMSocialControllerService defaultControllerService],YES);
        [UMSocialData defaultData].extConfig.wechatTimelineData.url = self.shareUrl;
        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:[NSString stringWithFormat:@"%@",    commdity.title] image:image1 location:nil urlResource:urlResource presentedController:self completion:^(UMSocialResponseEntity *response){
            if (response.responseCode == UMSResponseCodeSuccess) {
                NSLog(@"分享成功！");
            }
        }];
        
        
        
        
    }
    
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden=NO;
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    
       UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
    
    
    UIButton* sxBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 0.0,  60/2, 60/2)];
    [sxBtn setImage:[UIImage imageNamed:@"fenxiang"] forState:UIControlStateNormal];
    [sxBtn addTarget:self action:@selector(fenxiangss:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* myBtnBtn = [[UIBarButtonItem alloc] initWithCustomView:sxBtn];
    self.navigationItem.rightBarButtonItem = myBtnBtn;
    
  
    
    commdity =[HAODEsingleton shared];
 
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    
    [param setValue:commdity.reqId forKey:@"supplyId"];
    //    [param setValue:self.sats forKey:@"orderField"];
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    
    [HttpRequest requestData:@"/Discover/Supply/Detail" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                mainScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, ScreenWidth,ScreenHeight)];
                mainScroll.delegate = self;
                mainScroll.userInteractionEnabled = YES;
                mainScroll.scrollEnabled = YES;
                mainScroll.showsVerticalScrollIndicator = FALSE;
                mainScroll.showsHorizontalScrollIndicator = FALSE;
                mainScroll.backgroundColor=zuiqianhuicolor;
                [self .view addSubview:mainScroll];
                commdity.Dict=severDataDict.dataDict;
                UIImageView*image=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 150)];
                [image setImageWithURL:[severDataDict.dataDict objectForKey:@"imageUrl"] placeholderImage:nil];
                [mainScroll addSubview:image];
                view=[[UIView alloc]initWithFrame:CGRectMake(0, image.bottom, ScreenWidth, 340/2)];
                view.backgroundColor=[UIColor whiteColor];
                view.layer.borderWidth = 0.35;
                view.layer.borderColor = qianhuicolor.CGColor;
                [mainScroll addSubview:view];
                

                
                UIButton*phoneImage = [[UIButton alloc]init];
                phoneImage.frame = CGRectMake(20,130,20, 20);
                [phoneImage setImage:[UIImage imageNamed:@"dianhuasss"] forState:UIControlStateNormal];
                [view addSubview:phoneImage];
                UILabel*phone=[[UILabel alloc]initWithFrame:CGRectMake(0, 110, ScreenWidth/2, 60)];
                phone.text=[NSString stringWithFormat:@"%@", [severDataDict.dataDict objectForKey:@"phone"]];
                phone.textColor=shenhuicolor;
                phone.textAlignment=NSTextAlignmentCenter;
                phone.font=[UIFont systemFontOfSize:15];
                [view addSubview:phone];
                UIButton*jiantouBtnjiada = [[UIButton alloc]init];
                jiantouBtnjiada.frame = CGRectMake(0,100,ScreenWidth/2, 60);
                [jiantouBtnjiada addTarget:self action:@selector(phone:) forControlEvents:UIControlEventTouchUpInside];
                [view addSubview:jiantouBtnjiada];

                UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2, 125, 0.35, 30)];
                line.backgroundColor=qianhuicolor;
                [view addSubview:line];
                
                UIButton*addressImage = [[UIButton alloc]init];
                addressImage.frame = CGRectMake(ScreenWidth/2+20,130,20, 20);
                [addressImage setImage:[UIImage imageNamed:@"daohangsss"] forState:UIControlStateNormal];
                [view addSubview:addressImage];
                UILabel*address=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2+30, 110, ScreenWidth/2-40, 60)];
                address.text=[NSString stringWithFormat:@"%@", [severDataDict.dataDict objectForKey:@"address"]];
                address.textColor=shenhuicolor;
                address.textAlignment=NSTextAlignmentCenter;
                address.font=[UIFont systemFontOfSize:15];
                [view addSubview:address];
                UIButton*jiantouBtnjiada1 = [[UIButton alloc]init];
                jiantouBtnjiada1.frame = CGRectMake(ScreenWidth/2,110,ScreenWidth/2, 60);
                [jiantouBtnjiada1 addTarget:self action:@selector(address:) forControlEvents:UIControlEventTouchUpInside];
                [view addSubview:jiantouBtnjiada1];
                
                
                
                
                UILabel*title=[[UILabel alloc]initWithFrame:CGRectMake(20, 20, ScreenWidth-40, 16)];
                title.text=[severDataDict.dataDict objectForKey:@"title"];
                [view addSubview:title];
                
                NSMutableArray* arrrs=[severDataDict.dataDict objectForKey:@"tagList"];
                if (arrrs.count>0) {
                    
                    for (int i = 0,j = 0; i < arrrs.count; i++) {
                        if (i % 4 == 0) {
                            j++;
                        }
                        ProductView*clothView = [[ProductView alloc]initWithFrame:CGRectMake(20+60*(i%4), 5+(40*j), 55, 15)];
                        clothView.buttonView.titleLabel.textAlignment=NSTextAlignmentCenter;
                        clothView.buttonView.titleLabel.font=[UIFont systemFontOfSize:10];
                        clothView.buttonView.frame = CGRectMake(0, 0, 55, 15);
                        [clothView.buttonView setTitle: [[arrrs objectAtIndex:i] objectForKey:@"content"] forState:UIControlStateNormal];
                        clothView.buttonView.backgroundColor=[UIColor whiteColor];
                        [clothView.buttonView setTitleColor:luseColor forState:0];
                        clothView.buttonView.layer.borderColor=luseColor.CGColor;
                        clothView.buttonView.layer.borderWidth = 0.35;
                        [clothView.buttonView.layer setCornerRadius:2.0];
                        
                        [view addSubview:clothView];
                    }
                    
                }
                
                
                
                UILabel*intro=[[UILabel alloc]initWithFrame:CGRectMake(20, 80, ScreenWidth-40, 16)];
                intro.text=[severDataDict.dataDict objectForKey:@"intro"];
                intro.textColor=shenhuicolor;
                intro.font=[UIFont systemFontOfSize:15];
                [view addSubview:intro];
                UIImageView *_xianview2 = [[UIImageView alloc]initWithFrame:CGRectMake(15,110, ScreenWidth-30, 0.5)];
                _xianview2.image=[UIImage imageNamed:@"hengxian"];
                [view addSubview:_xianview2];
                
                
                
                
                
                UIView*details=[[UIView alloc]initWithFrame:CGRectMake(0, view.bottom+10, ScreenWidth, ScreenHeight)];
                details.backgroundColor=[UIColor whiteColor];
                details.layer.borderWidth = 0.35;
                details.layer.borderColor = qianhuicolor.CGColor;
                [mainScroll addSubview:details];
                
                UILabel*details1=[[UILabel alloc]initWithFrame:CGRectMake(20, 10, ScreenWidth-40, 45)];
                details1.text=@"商品信息";
                details1.textColor=shenhuicolor;
                details1.font=[UIFont systemFontOfSize:15];
                [details addSubview:details1];
                UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,55, ScreenWidth-30, 0.5)];
                _xianview.image=[UIImage imageNamed:@"hengxian"];
                [details addSubview:_xianview];
                [self guanzhu];
       
            }else{
                [Global hideProgressHUDInternal:self.view];
                
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
}
-(void)guanzhu{
    

    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    
    [param setValue:commdity.reqId forKey:@"supplyId"];
    NSLog(@"====%@",param);
    
    [HttpRequest requestData:@"/Discover/Supply/Products" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                scroll3 = [[UIScrollView alloc]initWithFrame:CGRectMake(0, view.bottom+65, ScreenWidth, 80)];
                scroll3.bounces = NO;
                [mainScroll addSubview:scroll3];
                
               product = [severDataDict.dataDict objectForKey:@"DataLine"];
                
                if (product.count>0) {
                    if (![product isEqual:[NSNull null]]) {
                        
                        for (int i = 0,j = -1; i < product.count; i++) {
                            if (i%2 == 0) {
                                j++;
                            }
                            proView = [[proview alloc]initWithFrame:CGRectMake(10+(ScreenWidth/2-5)*(i%2), 10+270*j, ScreenWidth/2-15, 230)];
                            
                            proView.label_name.text =[NSString stringWithFormat:@"%@ %@", [[product objectAtIndex:i] objectForKey:@"itemName"],[[product objectAtIndex:i] objectForKey:@"itemType"]];
                            NSString*GoldPrice=[NSString stringWithFormat:@"%@",[[product objectAtIndex:i] objectForKey:@"salePrice"]];
                            NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                            [numberFormatter setPositiveFormat:@"###,##0;"];
                            NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
                            proView.label_price.text =[NSString stringWithFormat:@"¥ %@",formattedNumberString ];

                           
                            
                          proView.daixiao = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2-15-65,proView.buttonView.bottom+33 , 65, 18)];
                            [ proView. daixiao setTitle:@"加入代销" forState:UIControlStateNormal];
                            if ([[[product objectAtIndex:i] objectForKey:@"isAgency"]isEqualToString:@"Y"]) {
                                 proView.daixiao. backgroundColor=qianhuicolor;
                            }else{
                                 proView.daixiao. backgroundColor=luseColor;
                                [ proView.daixiao addTarget:self action:@selector(daixiao:) forControlEvents: UIControlEventTouchUpInside];
                            
                            }
                            [ proView.daixiao setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                             proView.daixiao .titleLabel.font=[UIFont systemFontOfSize:13];
                           
                           
                            proView.daixiao.tag=i;
                            
                            
                            [proView addSubview: proView. daixiao];
                            
                            
                            [proView.imageView setImageWithURL:[NSURL URLWithString:[[product objectAtIndex:i] objectForKey:@"imageUrl"]] placeholderImage:nil];
                            
                            [proView.buttonView addTarget:self action:@selector(shangping:) forControlEvents:UIControlEventTouchUpInside];
                            [proView.buttonView setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                            [proView.buttonView setTitle:[[product objectAtIndex:i] objectForKey:@"itemId"] forState:UIControlStateNormal];
                            [scroll3 addSubview:proView];
                            
                        }
                        
                        scroll3.frame =CGRectMake(0, view.bottom+65, ScreenWidth, 270*(product.count/2+product.count%2)+50);
                        scroll3.contentSize = CGSizeMake(ScreenWidth, 270*(product.count/2+product.count%2)+50);
                    }
                    
                }
                [mainScroll setContentSize:CGSizeMake(ScreenWidth, scroll3.bottom)];
            }
            else{
                [Global hideProgressHUDInternal:self.view];
                
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
}

//代销
-(void)daixiao:(UIButton*)sender
{
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    
    [param setValue:[[product objectAtIndex:sender.tag] objectForKey:@"itemId"] forKey:@"itemId"];
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    
    [HttpRequest requestData:@"/Discover/Supply/Agency" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                
                [Global showTextHudSub:requestResultStr view:self.view];
                
                sender.backgroundColor=qianhuicolor;
                [sender setUserInteractionEnabled:NO];
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            NSLog(@"aaaaaaaa%@",severDataDict.dataDict);
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
    
}

-(void)shangping:(UIButton*)sender{
    
    
    [self sea1:[NSString stringWithFormat:@"%@",sender.titleLabel.text]];
    
}

- (void)sea1:(NSString *)String{
    //[self.data startAnimating];
    
    
    commdity.itemId=String;
    
    DiscoverSupplyAgencyViewController*vc1=[[DiscoverSupplyAgencyViewController alloc] init];
    
    [self.navigationController pushViewController:vc1 animated:YES];
    
    
}


-(void)phone:(UIButton *)sender{
    
    
    [ACETelPrompt callPhoneNumber:[commdity.Dict objectForKey:@"phone"]
                             call:^(NSTimeInterval duration) {
                                 NSLog(@"User made a call of %.1f seconds", duration);
                                 
                             } cancel:^{
                                 NSLog(@"User cancelled the call");
                             }];
    
    
    
    
    
    
    
    
}


-(void)address:(UIButton*)sender{
    commdity.adress=[commdity.Dict objectForKey:@"address"];
    NSString *oreillyAddress =commdity.adress;
    
    CLGeocoder *myGeocoder = [[CLGeocoder alloc] init];
    [myGeocoder geocodeAddressString:oreillyAddress completionHandler:^(NSArray *placemarks, NSError *error) {
        if ([placemarks count] > 0 && error == nil) {
            
            CLPlacemark *firstPlacemark = [placemarks objectAtIndex:0];
            double latitude=firstPlacemark.location.coordinate.longitude;
            NSString *latitudeString=[NSString stringWithFormat:@"%f",latitude];
            double longitude=firstPlacemark.location.coordinate.latitude;
            NSString *longitudeString=[NSString stringWithFormat:@"%f",longitude];
            NSLog(@"latitudeString= %@", longitudeString);
            NSLog(@"longitudeString= %@",latitudeString);
            NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                        commdity.adress,@"address",
                                        commdity.adress,@"city",
                                        @"google",@"from_map_type",
                                        commdity.adress,@"region", nil];
            
            [dic setValue:longitudeString forKey:@"google_lat"];
            [dic setValue:latitudeString forKey:@"google_lng"];
            
            NSLog(@"latitudeString= %@", longitudeString);
            NSLog(@"longitudeString= %@",latitudeString);
            
            
            MapViewControllers* h=[[MapViewControllers alloc] init];
            h.navDic=dic;
            h.mapType = RegionNavi;
            [self.navigationController pushViewController:h animated:YES];
            
            
            
        }
        else if ([placemarks count] == 0 && error == nil) {
            NSLog(@"Found no placemarks.");
        }
        else if (error != nil) {
            NSLog(@"An error occurred = %@", error); }
    }];
    
    
    
    
}

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}
@end